package com.example.light.web.meeting.service;

import com.example.light.common.util.SubstringUtil;
import com.example.light.web.meeting.dao.OaRoomMapper;
import com.example.light.web.meeting.entity.OaRoom;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;

import java.util.List;


@Service
public class OaRoomServiceImpl implements OaRoomService {
    @Autowired
    private OaRoomMapper roomMapper;

    @Override
    public void roomList(Model model) {
        List<OaRoom> roomList = roomMapper.queryRoom();
        SubstringUtil.delString(roomList);
        model.addAttribute("roomList", roomList);
    }

    @Override
    public void addRoom(OaRoom room) {
        roomMapper.insertSelective(room);
    }

    @Override
    public OaRoom querySingle(int id, Model model) {
        OaRoom room=roomMapper.selectByPrimaryKey(id);
        return room;
    }

    @Override
    public void addModel(Model model,OaRoom room) {
        model.addAttribute("userId",room.getUserId());
        model.addAttribute("roomSize",room.getRoomSize());
        model.addAttribute("roomAddress",room.getRoomAddress());
        model.addAttribute("roomPerson",room.getRoomPerson());
        model.addAttribute("roomUsedStart",room.getRoomUsedStart());
        model.addAttribute("roomUsedEnd",room.getRoomUsedEnd());
        model.addAttribute("roomId",room.getRoomId());
    }

    @Override
    public void editRoom(OaRoom room) {
        roomMapper.updateByPrimaryKeySelective(room);
    }

    @Override
    public void delRoom(int[] delInfo) {
        for (int i=0;i<delInfo.length;i++){
            roomMapper.deleteByPrimaryKey(delInfo[i]);
        }
    }

}
